using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace _18miljard.Db
{
	public class ResultSet
	{
		ResultSetColumnCollection columns;

		internal ResultSet()
		{
			this.columns = new ResultSetColumnCollection();
		}

		//To get an empty ResultSet
		internal ResultSet(ResultSetColumnCollection columns)
			: this()
		{
			foreach (string name in columns.Names)
			{
				this.columns.Add(name);
			}
		}

		public ResultSetColumnCollection Columns
		{
			get { return this.columns; }
		}

		public object this[int row, int column]
		{
			get
			{
				try
				{
					return this.columns[column][row];
				}
				catch
				{
					return null;
				}
			}
		}

		public object this[int row, string column]
		{
			get
			{
				ArrayList list = this.columns[column];
				if (list == null || row >= list.Count)
					return null;

				return list[row];
			}
		}

		public int Count
		{
			get
			{
				if (this.columns.Count > 0)
				{
					return this.columns[0].Count;
				}

				return -1;
			}
		}

		internal void AddRow(object[] values)
		{
			int count = values.GetLength(0);

			for (int i = 0; i < count; i++)
			{
				object value = values[i];

				this.columns[i].Add(value == null ? string.Empty : value);
			}
		}
	}
}
